package com.letoken.platform.admin.util;

import com.letoken.platform.repo.admin.req.user.QueryLineChartReq;
import com.letoken.platform.repo.admin.res.user.QueryLineChartRes;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wyl
 * @date 2023/4/14 17:53
 * @Version 1.0
 */
public class LineChartUtil {
    /**
     * 返回完整内容的折线图
     */
    public static List<QueryLineChartRes> getLineChartRes(List<LocalDate> lineChartTime, List<QueryLineChartRes> lineChartRes) {
        List<QueryLineChartRes> resList = new ArrayList<>();
        for (LocalDate localDate : lineChartTime) {
            QueryLineChartRes lineChart = new QueryLineChartRes();
            boolean flag = false;
            for (QueryLineChartRes res : lineChartRes) {
                if (localDate.equals(res.getTime())) {
                    flag = true;
                    lineChart.setTime(res.getTime());
                    lineChart.setNum(res.getNum());
                    resList.add(lineChart);
                    break;
                }
            }
            if (!flag) {
                lineChart.setTime(localDate);
                lineChart.setNum(BigDecimal.ZERO);
                resList.add(lineChart);
            }
        }
        return resList;
    }
}
